package saling_ticket.service;

public class SellingTicket_SynFunc implements  Runnable {

    private  int  ticket=55;

    @Override
    public void run() {
        while(true){

                    sellTicket();

                    if(ticket<=0){
                         break;
                    }

                }
        }
    public synchronized void sellTicket(){
        if(ticket>0){
            System.out.println(Thread.currentThread().getName() + "卖出了第" + ticket-- + "张票");//
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

